$(function () {
    WuLiaoGongXu()
})

function fh() {
    location.href = "../../li_meng/mdesignprocedureUP(1)(01).html";
}

let list = [];

function WuLiaoGongXu() {
    let mdesignprocedureUP = JSON.parse(localStorage.getItem("mdesignprocedureUP"));
    $("#rname").val(mdesignprocedureUP.checker);
    $("#date").val(mdesignprocedureUP.checktime);
    //工序设计单编号
    $("#designid").text(mdesignprocedureUP.designid);

    //工序名称
    let mDesignProcedureDetails = JSON.parse(localStorage.getItem("mdesignprocedureUP(1)"));
    $("#procedurename").text(mDesignProcedureDetails.procedurename)

    let shu = JSON.parse(localStorage.getItem("shuliangList"));
    $.ajax({
        type: "post",
        url: "/Mdesignproceduremoduledetails.do/limengUpDateChamDesignProcedureModuleDetails",
        data: {id: mDesignProcedureDetails.id},
        success: function (data) {
            list = data;
            let tr = "<tr>\n" +
                "       <th>序号</th>\n" +
                "       <th>物料名称</th>\n" +
                "       <th>物料编号</th>\n" +
                "       <th>描述</th>\n" +
                "       <th>本工序数量</th>\n" +
                "       <th>单位</th>\n" +
                "       <th>单价（元）</th>\n" +
                "       <th>小计(元)</th>\n" +
                "       </tr>";
            for (let i = 0; i < data.length; i++) {
                tr += "<tr>\n" +
                    "       <td>" + data[i].id + "</td>\n" +
                    "       <td>" + data[i].productname + "</td>\n" +
                    "       <td>" + data[i].productid + "</td>\n" +
                    "       <td>" + data[i].productdescribe + "</td>\n" +
                    "       <td><input value='" + shu[i] + "' class='shu' readonly></td>\n" +
                    "       <td>" + data[i].amountunit + "</td>\n" +
                    "       <td>" + data[i].costprice + "</td>\n" +
                    "       <td><span class='xiaojiao'>" + (data[i].costprice * shu[i]) + "</span></td>\n" +
                    "       </tr>"
            }
            $("#tableAdd").html(tr)
        }
    })
}

function TiJiao() {
    let mdesignprocedure = localStorage.getItem("mdesignprocedureUP");
    let MDesignProcedureDetails = localStorage.getItem("mdesignprocedureUP(1)");
    let shu = localStorage.getItem("shuliangList");
    let DModuleDetails = JSON.stringify(list);

    $.post("/Mdesignprocedure.do/LiMengUpDateMdesignprocedure", {
            MDesignProcedureDetails: MDesignProcedureDetails,shu: shu,
            mDesignProcedureModuleDetails: DModuleDetails,mdesignprocedure:mdesignprocedure
        },
        function (sdate) {
            $("#tishi").text("提交成功！")
            $("#tishi").css("color", "lime")
            $("#staticBackdrop").modal("show");
        })
}

//提交后跳页面
function hh() {
    localStorage.removeItem("shuliangList");
    localStorage.removeItem("mdesignprocedureUP(1)");
    location.href = "../../li_meng/mdesignprocedureUP(1).html";
}
